package com.red.selling.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.red.common.annotation.Log;
import com.red.common.core.controller.BaseController;
import com.red.common.core.domain.AjaxResult;
import com.red.common.enums.BusinessType;
import com.red.selling.domain.RedDelivery;
import com.red.selling.service.IRedDeliveryService;
import com.red.common.utils.poi.ExcelUtil;
import com.red.common.core.page.TableDataInfo;

/**
 * 销售送货单Controller
 * 
 * @author bug2222
 * @date 2024-11-20
 */
@RestController
@RequestMapping("/selling/delivery")
public class RedDeliveryController extends BaseController
{
    @Autowired
    private IRedDeliveryService redDeliveryService;

    /**
     * 查询销售送货单列表
     */
    @PreAuthorize("@ss.hasPermi('selling:delivery:list')")
    @GetMapping("/list")
    public TableDataInfo list(RedDelivery redDelivery)
    {
        startPage();
        List<RedDelivery> list = redDeliveryService.selectRedDeliveryList(redDelivery);
        return getDataTable(list);
    }

    /**
     * 导出销售送货单列表
     */
    @PreAuthorize("@ss.hasPermi('selling:delivery:export')")
    @Log(title = "销售送货单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RedDelivery redDelivery)
    {
        List<RedDelivery> list = redDeliveryService.selectRedDeliveryList(redDelivery);
        ExcelUtil<RedDelivery> util = new ExcelUtil<RedDelivery>(RedDelivery.class);
        util.exportExcel(response, list, "销售送货单数据");
    }

    /**
     * 获取销售送货单详细信息
     */
    @PreAuthorize("@ss.hasPermi('selling:delivery:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(redDeliveryService.selectRedDeliveryById(id));
    }

    /**
     * 新增销售送货单
     */
    @PreAuthorize("@ss.hasPermi('selling:delivery:add')")
    @Log(title = "销售送货单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RedDelivery redDelivery)
    {
        return toAjax(redDeliveryService.insertRedDelivery(redDelivery));
    }

    /**
     * 修改销售送货单
     */
    @PreAuthorize("@ss.hasPermi('selling:delivery:edit')")
    @Log(title = "销售送货单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RedDelivery redDelivery)
    {
        return toAjax(redDeliveryService.updateRedDelivery(redDelivery));
    }

    /**
     * 删除销售送货单
     */
    @PreAuthorize("@ss.hasPermi('selling:delivery:remove')")
    @Log(title = "销售送货单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(redDeliveryService.deleteRedDeliveryByIds(ids));
    }
}
